package org.wal.userdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import org.wal.userdemo.DTO.req.UserDTOReq;
import org.wal.userdemo.entity.UserEntity;
import org.wal.userdemo.service.UserService;
import org.wal.userdemo.utils.Result;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 获取用户信息
     * @param id
     * @return
     */
    @GetMapping("/getUserById")
    public UserEntity getUserById(@RequestParam("id") Integer id) {
        return userService.getUserById(id);
    }
    /**
     * 获取所有用户信息
     * @return List<UserEntity>
     */
    @PostMapping("/getAllUsers")
    public Result<List<UserEntity>> getAllUsers(@RequestBody UserDTOReq userDTOReq) {
        return Result.success(userService.getAllUsers(userDTOReq));
    }
    /**
     * 获取用户数量
     * @return Integer
     */
    @GetMapping("/getUserCount")
    public Integer getUserCount() {
        return userService.getUserCount();
    }
    /**
     * 获取用户分页信息
     * @param pageNum
     * @param pageSize
     * @return List<UserEntity>
     */
    @GetMapping("/getUsersByPage")
    public List<UserEntity> getUsersByPage(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        return userService.getUsersByPage(pageNum, pageSize);
    }
    /**
     * 获取用户名称模糊查询信息
     * @param name
     * @return List<UserEntity>
     */
    @GetMapping("/getUsersByName")
    public List<UserEntity> getUsersByName(@RequestParam("name") String name) {
        return userService.getUsersByName(name);
    }
    /**
     * 添加用户信息
     * @param userEntity
     * @return Integer
     */
    @PostMapping("/addUser")
    public Integer addUser(@RequestBody UserEntity userEntity) {
        return userService.addUser(userEntity);
    }
    /**
     * 修改用户信息
     * @param userEntity
     * @return Integer
     */
    @PostMapping("/updateUser")
    public Integer updateUser(@RequestBody UserEntity userEntity) {
        return userService.updateUser(userEntity);
    }
    /**
     * 删除用户信息
     * @param id
     * @return Integer
     */
    @GetMapping("/deleteUser")
    public Integer deleteUser(@RequestParam("id") Integer id) {
        return userService.deleteUser(id);
    }

}

